// shengchanliuchengLocal.js 生产流程本地存储操作工具，包含增删查改等方法
const STORAGE_KEY = 'shengchanliucheng';

export function getLiuchengList() {
  return JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]');
}

export function saveLiuchengList(list) {
  localStorage.setItem(STORAGE_KEY, JSON.stringify(list));
}

export function addLiucheng(item) {
  const list = getLiuchengList();
  item.id = Date.now();
  list.push(item);
  saveLiuchengList(list);
}

export function updateLiucheng(item) {
  const list = getLiuchengList();
  const idx = list.findIndex(i => i.id === item.id);
  if (idx !== -1) {
    list[idx] = item;
    saveLiuchengList(list);
  }
}

export function deleteLiucheng(ids) {
  let list = getLiuchengList();
  list = list.filter(i => !ids.includes(i.id));
  saveLiuchengList(list);
}

export function getLiuchengById(id) {
  return getLiuchengList().find(i => i.id === id);
} 